package com.fangcun.controller.api.old;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fangcun.bean.sys.ResponseMsg;
import com.fangcun.common.canstant.ErrCode;
import com.fangcun.common.exception.ProException;
import com.fangcun.common.util.PublicMethod;
import com.fangcun.common.util.apiversion.ApiVersion;
import com.fangcun.common.util.base.BaseController;
import com.fangcun.entity.UserVirtualWallet;
import com.fangcun.service.api.UserVirtualWalletService;

@RestController
@RequestMapping("/api/{version}/auth/user")
public class UserVirtualWalletController extends BaseController {
	
	private static Logger LOG = LoggerFactory.getLogger(UserVirtualWalletController.class);

	@Autowired
	private UserVirtualWalletService userVirtualWalletService;
	/** 查询 钱包**/
	@ApiVersion(1.0)
	@RequestMapping("wallet")
	private ResponseMsg wallet() {
		ResponseMsg msg =ResponseMsg.returnBeanBuild();
		try {
			msg.setData(userVirtualWalletService.wallet(getApiUserId()));
		} catch (ProException e) {
			LOG.error("-钱包展示出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-钱包展示异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	/****/
	@ApiVersion(1.0)
	@RequestMapping("wallet/update")
	private ResponseMsg update(@RequestBody UserVirtualWallet request) {
		ResponseMsg msg =ResponseMsg.returnBeanBuild();
		try {
			userVirtualWalletService.update(request);
		} catch (ProException e) {
			LOG.error("-修改密码出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-修改密码异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
